<template>
  <div class="opration">
    <div class="oprationLeft">
      <bs-add-button-icon
        @click.native="doAdd"
        v-has="'SYS_ROLE_SAVE'"
      ></bs-add-button-icon>
      <bs-delete-button-icon
        @click.native="doDel"
        v-has="'SYS_ROLE_DELETE'"
      ></bs-delete-button-icon>
      <bs-edit-button-icon
        @click.native="doEdit"
        v-has="'SYS_ROLE_UPDATE'"
      ></bs-edit-button-icon>
      <bs-refresh-button-icon
        @click.native="doRefresh"
      ></bs-refresh-button-icon>
      <!-- v-has="'SYS_SYS_ROLE_SAVE_ROLE'" -->
      <!-- <el-select class="show-item" size="small" v-model="showItem" placeholder="显示子元素" clearable style="width:105px;">
            <el-option label="显示子元素" value="show"></el-option>
      <el-option label="隐藏子元素" value="hide"></el-option>-->
      <!-- </el-select> -->
    </div>
  </div>
</template>
<script>
export default {
  name: 'ManageCondition',
  data() {
    return {
      selectRow: null,
      permissionList: [],
    }
  },
  components: {},
  created() {
    this.$eventBus.$on('selectRow', this.handleSelectRow)
    this.$eventBus.$on('updatePermissionList', this.updatePermission)
  },
  beforeDestroy() {
    this.$eventBus.$off('selectRow')
    this.$eventBus.$off('updatePermissionList')
  },
  methods: {
    updatePermission(permissions) {
      this.permissionList = permissions
    },
    doAdd() {
      console.log('doAdd')
      const actor = {
        name: '',
        unauthed: this.permissionList,
      }
      this.$eventBus.$emit('addDialogShow', actor, true)
    },
    doEdit() {
      if (!this.selectRow) {
        this.$alert(this.$t('提示'), this.$t('请选择一个要修改的角色'))
        return
      }

      this.$eventBus.$emit('addDialogShow', this.selectRow, false)
    },
    doDel() {
      if (!this.selectRow) {
        this.$alert(this.$t('提示'), this.$t('请选择一个要删除的角色'))
        return
      }
      this.$confirm(this.$t('提示'), this.$t('是否确定删除')).then((bool) => {
        if (bool) {
          let params = {
            id: this.selectRow.id,
          }
          this.$store.dispatch('system/deleteRole', params).then((res) => {
            //更新列表
            this.$success('del')
            this.$eventBus.$emit('refreshActorlist',false)
          })
        }
      })
    },
    doRefresh() {
      this.$eventBus.$emit('refreshActorlist',true)
    },
    handleSelectRow(val) {
      this.selectRow = val
      console.log(this.selectRow)
    },
  },
}
</script>

<style lang="scss" scoped>
.opration {
  display: flex;
  flex-flow: row;
  justify-content: space-between;
  .oprationLeft button {
    margin: 0 12px 17px 0;
  }
}

</style>